﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;
using System.ComponentModel;
using AdaptiveHelpDesk;

namespace Novice.Services
{
    /// <summary>
    /// Summary description for DropdownLists
    /// </summary>
    [WebService(Namespace = "http://soaiui.nmmu.ac.za/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class DropdownLists : System.Web.Services.WebService
    {
        StoredProcedures sp = new StoredProcedures();

        [WebMethod]
        public List<string> getListElements(string name)
        {
            // For each element, get the data and return list
            switch (name)
            {
                default: return new List<string>();
                case "serviceName": return addListName(getServiceNames(), name);
                case "callType": return addListName(getCallType(), name);
                case "subCallType": return addListName(getSubCallType(), name);

                case "priority": return addListName(getPriority(), name);
                case "source": return addListName(getCallSource(), name);

                case "Campus": return addListName(getCampuses(), name);
                case "Contact": return addListName(getContacts(), name);
                
                case "Cause": return addListName(getCause(), name);
                case "Solution": return addListName(getHowResolved(), name);
            }
        }

        /// <summary>
        /// Adds the name of the Element at the end of the list
        /// </summary>
        /// <param name="list">list to which name is added</param>
        /// <param name="name">name to add at the end of the list</param>
        /// <returns></returns>
        public List<string> addListName(List<string> list, string name)
        {
            list.Add(name);
            return list;
        }

        #region Log Call DDLs

        [WebMethod]
        public List<String> getServiceNames()
        {
            return ((BindingList<string>)sp.getServiceNames()).ToList<string>();
        }

        [WebMethod]
        public List<String> getCallType()
        {
            return (convert(sp.getCallTypeALL()));
        }

        [WebMethod]
        public List<String> getSubCallType()
        {
            return (convert(sp.getSubCallTypeALL()));
        }

        [WebMethod]
        public List<String> getPriority()
        {
            return ((BindingList<string>)sp.getPriority()).ToList<string>();
        }

        [WebMethod]
        public List<String> getCallSource()
        {
            return ((BindingList<string>)sp.getCallSource()).ToList<string>();
        }
        #endregion

        #region Assign Call DDLs
        [WebMethod]
        public List<String> getContacts()
        {
            return ((BindingList<string>)sp.getAssigneeIDAll()).ToList<string>();
        }

        [WebMethod]
        public List<string> getCampuses()
        {
            return ((BindingList<string>)sp.getCampus()).ToList<string>();
        }

        #endregion

        #region Call Resolution DDLs
        [WebMethod]
        public List<String> getHowResolved()
        {
            return ((BindingList<string>)sp.getResolvedHow()).ToList<string>(); 
        }

        [WebMethod]
        public List<String> getCause()
        {
            return (convert(sp.getCauseAll()));
        }
        #endregion

        public List<string> convert(string[,] list)
        {
            List<string> temp = new List<string>();

            //Do conversion
            foreach (string item in list)
            {
                temp.Add(item);
            }
            return temp;
        }
    }
}
